package com.loong.web.gp4j.component.intercept;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.loong.web.gp4j.bean.schema.error.Errors;
import com.loong.web.gp4j.service.error.ErrorService;
import com.loong.web.suppert.intercept.checkpoint.MaliciousHandler;

/**
 * 恶意请求处理组件
 *
 * @author 张成轩
 */
public class CheckpointComponent implements MaliciousHandler {

	@Resource
	private ErrorService errorService;

	@Override
	public void ip(HttpServletRequest request, HttpServletResponse response) throws IOException {

		response.getWriter().write("Your IP has been included in the blacklist, the server refused to visit!");
		errorService.error(request, Errors.MALICE_IP);
	}

	@Override
	public void url(HttpServletRequest request, HttpServletResponse response) throws IOException {

		response.getWriter().write("Your request may contains malicious information, the server refused to visit!");
		errorService.error(request, Errors.MALICE_URL);
	}

	@Override
	public void param(HttpServletRequest request, HttpServletResponse response) throws IOException {

		response.getWriter().write("Your request may contains malicious information, the server refused to visit!");
		errorService.error(request, Errors.MALICE_PARAM);
	}
}
